<!--
 * Description: 报价系列主页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Dongxu.Ni
 * Date: 2020/04/14 02:52
-->

<template>
  <BaseWrap>
    <!-- 查询条件 -->
    <BaseFunc
      :is-requesting="isRequesting"
      :query-form="queryForm"
      :visible.sync="advanceOptionDrawer"
      @query="query"
    >
      <template slot="btn">
        <el-button
          v-if="$hasPer('add')"
          class="btn-custom"
          icon="el-icon-circle-plus-outline"
          plain
          size="mini"
          type="primary"
          @click="addDialogVisible = true"
        >
          {{ $t('button.add') }}
        </el-button>
      </template>
      <template>
        <!--抽屉内部查询表单-->
        <el-form class="g-advance-drawer-form" label-width="100px" :model="queryForm" size="medium">
          <el-row>
            <!--系列编号-->
            <el-col :span="8">
              <el-form-item :label="$t('Series.seriesId')">
                <el-input v-model="queryForm.seriesId" clearable />
              </el-form-item>
            </el-col>

            <!--ME负责人-->
            <el-col :span="8">
              <el-form-item :label="$t('Series.meOwner')">
                <el-select
                  v-model="queryForm.meOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getMEGcmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!--EE负责人-->
            <el-col :span="8">
              <el-form-item :label="$t('Series.eeOwner')">
                <el-select
                  v-model="queryForm.eeOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getEEGcmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <!--PKG负责人-->
            <el-col :span="8">
              <el-form-item :label="$t('Series.pkgOwner')">
                <el-select
                  v-model="queryForm.pkgOwner"
                  clearable
                  filterable
                  :placeholder="$t('select.placeholder')"
                >
                  <el-option
                    v-for="item in $store.getters['user/getPKGGcmUserSimpleCollects']"
                    :key="item.userId"
                    :label="item.userName"
                    :value="item.userId"
                  >
                    <span style="float: left;">{{ item.userName }}</span>
                    <span style="float: right; color: #b4b4b4; font-size: 12px">
                      {{ item.gcmFunction + ' ' + item.team }}
                    </span>
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>
    </BaseFunc>

    <BaseTable
      :is-requesting="isRequesting"
      :page-number.sync="pageNumber"
      :page-size.sync="pageSize"
      :table-data="tableData"
      :total="total"
      @query="query"
    >
      <template slot="header">
        <!--序号列-->
        <el-table-column align="center" fixed :label="$t('table.NO')" min-width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
      </template>

      <template>
        <!--系列编号列-->
        <el-table-column
          align="center"
          :label="$t('Series.seriesId')"
          prop="seriesId"
          sortable
          width="150px"
        />
        <!--ME负责人列-->
        <el-table-column
          align="center"
          :label="$t('Series.meOwner')"
          min-width="150px"
          prop="meOwner"
          sortable
        >
          <template slot-scope="scope">
            <span>{{ $store.getters['user/getUserNameById'](scope.row.meOwner) }}</span>
          </template>
        </el-table-column>
        <!--EE负责人列-->
        <el-table-column
          align="center"
          :label="$t('Series.eeOwner')"
          min-width="150px"
          prop="eeOwner"
          sortable
        >
          <template slot-scope="scope">
            <span>{{ $store.getters['user/getUserNameById'](scope.row.eeOwner) }}</span>
          </template>
        </el-table-column>
        <!--PKG负责人列-->
        <el-table-column
          align="center"
          :label="$t('Series.pkgOwner')"
          min-width="150px"
          prop="pkgOwner"
          sortable
        >
          <template slot-scope="scope">
            <span>{{ $store.getters['user/getUserNameById'](scope.row.pkgOwner) }}</span>
          </template>
        </el-table-column>
      </template>
      <template slot="end">
        <!--操作列-->
        <el-table-column
          v-if="$hasPer('edit') || $hasPer('delete')"
          align="center"
          fixed="right"
          :label="$t('table.operate')"
          min-width="150px"
        >
          <template slot-scope="scope">
            <el-button
              v-if="$hasPer('edit')"
              size="mini"
              type="text"
              @click="rowEdit(scope.$index, scope.row)"
            >
              <i class="el-icon-edit el-icon--right"></i>
              {{ $t('button.edit') }}
            </el-button>
            <el-button
              v-if="$hasPer('delete')"
              size="mini"
              type="text"
              @click="rowDelete(scope.$index, scope.row)"
            >
              <i class="el-icon-delete el-icon--right"></i>
              {{ $t('button.delete') }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </BaseTable>
    <!--新增对话框-->
    <el-dialog
      v-if="addDialogVisible"
      center
      :title="$t('dialog.add')"
      top="5vh"
      :visible.sync="addDialogVisible"
      width="50%"
    >
      <series-add @cancel="addDialogVisible = false" @save="afterAddSave" />
    </el-dialog>
    <!--编辑对话框-->
    <el-dialog
      v-if="editDialogVisible"
      center
      :title="$t('dialog.edit')"
      top="5vh"
      :visible.sync="editDialogVisible"
      width="50%"
    >
      <series-edit
        :input-data="currentEditRow"
        @cancel="editDialogVisible = false"
        @save="afterEditSave"
      />
    </el-dialog>
  </BaseWrap>
</template>

<script>
import { seriesDelete, seriesPageList } from '../../../api/quote/series'
import SeriesAdd from './components/SeriesAdd'
import SeriesEdit from './components/SeriesEdit'

export default {
  name: 'Series',
  components: { SeriesAdd, SeriesEdit },
  props: {},
  data() {
    return {
      // 正在查询
      isRequesting: false,
      // 高级查询选项抽屉弹出标识
      advanceOptionDrawer: false,
      // 页码
      pageNumber: 1,
      // 页展示行数
      pageSize: 10,
      // 总行数
      total: 0,
      // 表格数据
      tableData: [],
      // 查询表单对象
      queryForm: {
        seriesId: '',
        meOwner: '',
        eeOwner: '',
        pkgOwner: ''
      },
      // 新增对话框可见标识
      addDialogVisible: false,
      // 编辑对话框可见标识
      editDialogVisible: false,
      // 当前编辑行的数据
      currentEditRow: {}
    }
  },
  computed: {},
  watch: {},
  created() {
    this.pageDataInit()
  },
  mounted() {},
  methods: {
    /* 页面数据初始化*/
    pageDataInit() {
      this.query()
    },
    /* 查询表格数据*/
    async query() {
      try {
        this.isRequesting = true
        this.advanceOptionDrawer = false
        const res = await seriesPageList({
          pageSize: this.pageSize,
          pageNumber: this.pageNumber,
          pageCondition: this.queryForm
        })
        this.tableData = res.data.list
        this.total = res.data.total
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    /* 行记录编辑*/
    rowEdit(index, row) {
      this.currentEditRow = row
      this.editDialogVisible = true
    },
    /* 行记录删除 */
    rowDelete(index, row) {
      this.$confirmBox(this.$t('button.delete'), 'error')
        .then(() => {
          seriesDelete({ seriesId: row.seriesId }, { msgSuccess: true, msgError: true }).then(
            () => {
              this.query()
            }
          )
        })
        .catch(cancel => cancel)
    },
    // 新增保存之后
    afterAddSave() {
      this.addDialogVisible = false
      this.query()
    },
    // 修改保存之后
    afterEditSave() {
      this.editDialogVisible = false
      this.query()
    }
  }
}
</script>

<style scoped></style>
